package com.acce.gxsc.model;

import com.acce.gxsc.common.Constants;
import com.acce.gxsc.common.Tools;
import com.acce.gxsc.model.http.HttpClient;
import com.acce.gxsc.model.http.rxjava.Result;
import com.acce.gxsc.model.loaclBean.DutyLogBean;
import com.acce.gxsc.model.loaclBean.InCarIdBean;
import com.acce.gxsc.model.loaclBean.InCarListBean;
import com.acce.gxsc.model.loaclBean.LocalFeeCarDetailBean;
import com.acce.gxsc.model.loaclBean.PregisterInfoBean;
import com.acce.gxsc.model.loaclBean.PregisterListBean;
import com.acce.gxsc.model.loaclBean.ResultBean;
import com.acce.gxsc.model.netBean.CarPredictionBean;
import com.acce.gxsc.model.netBean.DutyBean;
import com.acce.gxsc.model.netBean.GoodsListBean;
import com.acce.gxsc.model.netBean.InGoodsBean;
import com.acce.gxsc.model.netBean.NetBatchDetailBean;
import com.acce.gxsc.model.netBean.NetCompanyBean;
import com.acce.gxsc.model.netBean.NetInBatchListBean;
import com.acce.gxsc.model.netBean.NetInCarInfo;
import com.acce.gxsc.model.netBean.NetInCarListBean;
import com.acce.gxsc.model.netBean.NetInCarReport;
import com.acce.gxsc.model.netBean.NetOutCarBatchDetailBean;
import com.acce.gxsc.model.netBean.NetOutCarReport;
import com.acce.gxsc.model.netBean.NetSimilarCarInfo;
import com.acce.gxsc.model.netBean.NetSupervisionDutyListBean;
import com.acce.gxsc.model.netBean.NetSupervisionListBean;
import com.acce.gxsc.model.netBean.NetWorkAreaListBean;
import com.acce.sdk.BaseApp;
import com.acce.sdk.BaseConstants;
import com.acce.sdk.BaseReceiver;
import com.acce.sdk.User;
import com.acce.sdk.base.volleyHttp.BusinessBuild;
import com.acce.sdk.model.LoginModel;
import com.acce.sdk.utils.LogUtils;
import com.acce.sdk.utils.ToastUtils;

import java.util.ArrayList;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

import static com.acce.gxsc.common.App.dutyId;

/**
 * Created by huxley on 2017/5/27.
 */
public class WorkModel {

    private static WorkModel instance;

    private WorkModel() {
    }

    public static WorkModel getInstance() {
        if (instance == null) {
            synchronized (WorkModel.class) {
                if (instance == null) {
                    instance = new WorkModel();
                }
            }
        }
        return instance;
    }

    public Observable<ResultBean<DutyLogBean>> loadWork() {
        return HttpClient.getAcceApi()
                .loadWork(Constants.ServiceCode.LOAD_WORK, new BusinessBuild().build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new Func1<ResultBean<DutyLogBean>, ResultBean<DutyLogBean>>() {
                    @Override
                    public ResultBean<DutyLogBean> call(ResultBean<DutyLogBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<DutyBean>> startWork(String logoType, String gateNo, String workNo) {
        return HttpClient.getAcceApi()
                .startWork(Constants.ServiceCode.START_WORK, new BusinessBuild()
                        .addBusinessParam1("logoType", logoType)
                        .addBusinessParam1("marketName", "广州江秾汇市场服务管理有限公司")
                        .addBusinessParam1("gateNo", gateNo)
                        .addBusinessParam1("workNo", workNo)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<DutyBean>, ResultBean<DutyBean>>() {
                    @Override
                    public ResultBean<DutyBean> call(ResultBean<DutyBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<DutyBean>> workAgain(String dutyId) {
        return HttpClient.getAcceApi()
                .workAgain(Constants.ServiceCode.WORK_AGAIN, new BusinessBuild()
                        .addBusinessParam1("dutyId", dutyId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<DutyBean>, ResultBean<DutyBean>>() {
                    @Override
                    public ResultBean<DutyBean> call(ResultBean<DutyBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);

                    }
                });
    }


    public Observable<ResultBean<Object>> endWork(String dutyId) {
        return HttpClient.getAcceApi()
                .endWork(Constants.ServiceCode.END_WORK, new BusinessBuild()
                        .addBusinessParam1("dutyId", dutyId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<GoodsListBean>> loadGoodsList() {
        return HttpClient.getAcceApi()
                .loadGoodsList(Constants.ServiceCode.LOAD_GOODS_LIST, new BusinessBuild().build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<GoodsListBean>, ResultBean<GoodsListBean>>() {
                    @Override
                    public ResultBean<GoodsListBean> call(ResultBean<GoodsListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<Object>> registerCar(CarPredictionBean data) {
        return HttpClient.getAcceApi()
                .registerCar(Constants.ServiceCode.REGISTER_CAR, new BusinessBuild()
                        .addBusinessParam1("consignorNick", data.consignorNick) //收发货单位
                        .addBusinessParam1("declareCompanyNick", data.declareCompanyNick) //申报单位
                        .addBusinessParam1("preContainNo", data.preContainNo) //申报货柜号
                        .addBusinessParam1("preContainSize", data.preContainSize) //申报货柜尺寸
                        .addBusinessParam1("owerName", data.owerName) //货主姓名
                        .addBusinessParam1("contactPhone", data.contactPhone) //货主联系电话
                        .addBusinessParam1("pregistergoods", data.pregistergoods) //商品
                        .addBusinessParam1("pregisterKey", data.pregisterKey) //商品
                        .addBusinessParam1("acceTemp1", data.acceTemp1) //商品

                        .addBusinessParam1("plateNumX", data.plateNumX) //车牌号
                        .addBusinessParam1("plateNumG", data.plateNumG) //车牌号
                        .addBusinessParam1("carHangNo", data.carHangNo) //车牌号

                        .addBusinessParam1("customsNo", "000") //商品
                        .addBusinessParam1("consignor", "000") //商品
                        .addBusinessParam1("declareCompany", "000") //商品
                        .addBusinessParam1("plateNum", "000") //商品
                        .addBusinessParam1("containCompany", "000") //商品
                        .addBusinessParam1("driverName", "000") //商品
                        .addBusinessParam1("driverPhone", "000") //商品
                        .addBusinessParam1("pregisterBillNo", "000") //商品

//                        .addBusinessParam1("pregisterGateName", App.gateName)
                        .addBusinessParam1("dutyId", dutyId)

                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<PregisterListBean>> loadRegisterCarList(String time, String preContainNo, String pregisterBillState, String consignorNick, String declareCompanyNick) {
        return HttpClient.getAcceApi()
                .loadRegisterCarList(Constants.ServiceCode.LOAD_REGISTER_CAR_LIST, new BusinessBuild()
                        .addBusinessParam1("count", "30")
                        .addBusinessParam1("pregisterBillState", pregisterBillState)
                        .addBusinessParam1("preContainNo", preContainNo)
                        .addBusinessParam1("consignorNick", consignorNick)
                        .addBusinessParam1("declareCompanyNick", declareCompanyNick)
                        .addBusinessParam1("timestamp", time)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<PregisterListBean>, ResultBean<PregisterListBean>>() {
                    @Override
                    public ResultBean<PregisterListBean> call(ResultBean<PregisterListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetCompanyBean>> loadCompanyList() {
        return HttpClient.getAcceApi()
                .loadCompanyList(Constants.ServiceCode.LOAD_COMPANY_LIST, new BusinessBuild().build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetCompanyBean>, ResultBean<NetCompanyBean>>() {
                    @Override
                    public ResultBean<NetCompanyBean> call(ResultBean<NetCompanyBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }


    public Observable<ResultBean<PregisterInfoBean>> loadRegisterCarDetail(String pregisterKey) {
        return HttpClient.getAcceApi()
                .loadRegisterCarDetail(Constants.ServiceCode.LOAD_REGISTER_CAR_DETAIL,
                        new BusinessBuild().addBusinessParam1("pregisterKey", pregisterKey).build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<PregisterInfoBean>, ResultBean<PregisterInfoBean>>() {
                    @Override
                    public ResultBean<PregisterInfoBean> call(ResultBean<PregisterInfoBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<InCarIdBean>> inRoom(CarPredictionBean data) {
        return HttpClient.getAcceApi()
                .inRoom(Constants.ServiceCode.IN_ROOM, new BusinessBuild()
                        .addBusinessParam1("consignorNick", data.consignorNick) //收发货单位
                        .addBusinessParam1("declareCompanyNick", data.declareCompanyNick) //申报单位
                        .addBusinessParam1("preContainNo", data.preContainNo) //申报货柜号
                        .addBusinessParam1("preContainSize", data.preContainSize) //申报货柜尺寸
                        .addBusinessParam1("owerName", data.owerName) //货主姓名
                        .addBusinessParam1("contactPhone", data.contactPhone) //货主联系电话
                        .addBusinessParam1("pregistergoods", data.pregistergoods) //商品
                        .addBusinessParam1("pregisterKey", data.pregisterKey) //商品
                        .addBusinessParam1("acceTemp1", data.acceTemp1) //商品
                        .addBusinessParam1("plateNumX", data.plateNumX) //车牌号
                        .addBusinessParam1("plateNumG", data.plateNumG) //车牌号
                        .addBusinessParam1("hangNum", data.carHangNo) //车牌号
                        .addBusinessParam1("customsNo", "000") //商品
                        .addBusinessParam1("consignor", "000") //商品
                        .addBusinessParam1("declareCompany", "000") //商品
                        .addBusinessParam1("plateNum", "000") //商品
                        .addBusinessParam1("containCompany", "000") //商品
                        .addBusinessParam1("driverName", "000") //商品
                        .addBusinessParam1("driverPhone", "000") //商品
                        .addBusinessParam1("pregisterBillNo", "000") //商品
                        .addBusinessParam1("dutyId", dutyId)
                        .addBusinessParam1("parkArea",data.parkArea)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<InCarIdBean>, ResultBean<InCarIdBean>>() {
                    @Override
                    public ResultBean<InCarIdBean> call(ResultBean<InCarIdBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }
    public Observable<ResultBean<Object>> editCar(String inCarKey,String plateNum,String hangNum,String contactName){
        return HttpClient.getAcceApi().editCar(Constants.ServiceCode.EDIT_CAR,new BusinessBuild()
        .addBusinessParam1("inCarKey",inCarKey)
        .addBusinessParam1("plateNum",plateNum)
        .addBusinessParam1("hangNum",hangNum)
        .addBusinessParam1("contactName",contactName)
        .addBusinessParam1("goodsInfo","").build().toString()).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> objectResultBean) {
                        return handleResult(objectResultBean);
                    }
                });
    }

    public Observable<ResultBean<InCarListBean>> loadInCarList(String consignorNick, String declareCompanyNick, String diliveryType) {
        return HttpClient.getAcceApi()
                .loadInCarList(Constants.ServiceCode.LOAD_IN_CAR_LIST, new BusinessBuild()
                        .addBusinessParam1("consignorNick", consignorNick)
                        .addBusinessParam1("declareCompanyNick", declareCompanyNick)
                        .addBusinessParam1("diliveryType", diliveryType)
                        .addBusinessParam1("dutyId", dutyId)
                        .addBusinessParam1("post",User.getInstance().getCompanyAuthority())
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<InCarListBean>, ResultBean<InCarListBean>>() {
                    @Override
                    public ResultBean<InCarListBean> call(ResultBean<InCarListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }


    public Observable<ResultBean<NetInCarInfo>> loadInCarDetail(String inCarKey) {
        return HttpClient.getAcceApi()
                .loadInCarDetail(Constants.ServiceCode.LOAD_IN_CAR_DETAIL,
                        new BusinessBuild().addBusinessParam1("inCarKey", inCarKey).build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetInCarInfo>, ResultBean<NetInCarInfo>>() {
                    @Override
                    public ResultBean<NetInCarInfo> call(ResultBean<NetInCarInfo> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetInCarReport>> loadInCarForm() {
        return HttpClient.getAcceApi()
                .loadInCarForm(Constants.ServiceCode.LOAD_IN_CAR_FORM,
                        new BusinessBuild().addBusinessParam1("dutyId", dutyId).build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetInCarReport>, ResultBean<NetInCarReport>>() {
                    @Override
                    public ResultBean<NetInCarReport> call(ResultBean<NetInCarReport> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }


    private <T> ResultBean<T>  handleResult(ResultBean<T> result) {
        if (result == null || result.returnCode == null) {
            ToastUtils.show("网络请求异常");
            return result;
        }
        switch (result.returnCode) {
            case "00000960":
            case "00000929":
            case BaseConstants.ERROR_CODE_REMOTE_LOGIN:
            case BaseConstants.ERROR_CODE_NETWORK_ENVIRONMENT_CHANGE:
            case BaseConstants.ERROR_CODE_NETWORK_ENVIRONMENT_EXCEPTION:
                LoginModel loginModel = new LoginModel();
                loginModel.exitLogin(BaseApp.context);
                BaseReceiver.showLogoutDialog(BaseApp.context, "您的账号登录异常，请点击重新登录!");
                LogUtils.logout(result.returnCode);
                break;
        }
        return result;
    }

    public Observable<ResultBean<NetOutCarBatchDetailBean>> toOutCarDetail(String inCarId) {
        return HttpClient.getAcceApi()
                .toOutCarDetail(Constants.ServiceCode.TO_OUT_CAR_DETAIL,
                        new BusinessBuild().addBusinessParam1("inCarId", inCarId).build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetOutCarBatchDetailBean>, ResultBean<NetOutCarBatchDetailBean>>() {
                    @Override
                    public ResultBean<NetOutCarBatchDetailBean> call(ResultBean<NetOutCarBatchDetailBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<LocalFeeCarDetailBean>> getFeeCarDetail(String inCarId) {
        return HttpClient.getAcceApi()
                .getFeeCarDetail(Constants.ServiceCode.FEE_CAR_DETAIL,
                        new BusinessBuild().addBusinessParam1("queryId", inCarId).build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<LocalFeeCarDetailBean>, ResultBean<LocalFeeCarDetailBean>>() {
                    @Override
                    public ResultBean<LocalFeeCarDetailBean> call(ResultBean<LocalFeeCarDetailBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>> loadCarInMarketCount(String queryTime, String queryType) {
        return HttpClient.getAcceApi()
                .toOutCarCount(Constants.ServiceCode.QUERY_OUT_CAR_COUNT, new BusinessBuild()
                        .addBusinessParam1("queryType", queryType)
                        .addBusinessParam1("queryTime", queryTime)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>, ResultBean<com.acce.gxsc.model.netBean.InCarListBean>>() {
                    @Override
                    public ResultBean<com.acce.gxsc.model.netBean.InCarListBean> call(ResultBean<com.acce.gxsc.model.netBean.InCarListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>> loadCarInMarketList(String queryTime, String queryType, String timestamp, String direction) {
        return HttpClient.getAcceApi()
                .toOutCarList(Constants.ServiceCode.QUERY_OUT_CAR_LIST, new BusinessBuild()
                        .addBusinessParam1("count", 20)
                        .addBusinessParam1("queryType", queryType)
                        .addBusinessParam1("queryTime", queryTime)
                        .addBusinessParam1("direction", direction)
                        .addBusinessParam1("timestamp", timestamp)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>, ResultBean<com.acce.gxsc.model.netBean.InCarListBean>>() {
                    @Override
                    public ResultBean<com.acce.gxsc.model.netBean.InCarListBean> call(ResultBean<com.acce.gxsc.model.netBean.InCarListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<com.acce.gxsc.model.netBean.InCarListBean1>> loadCarInMarketList2(int pageNum, String diliveryType) {
        return HttpClient.getAcceApi()
                .toOutCarList1(Constants.ServiceCode.QUERY_OUT_CAR_LIST2, new BusinessBuild()
                        .addBusinessParam1("pageSize", 20)
                        .addBusinessParam1("pageNum", pageNum)
                        .addBusinessParam1("diliveryType", diliveryType)
                        /*
                        .addBusinessParam1("direction", direction)
                        .addBusinessParam1("timestamp", timestamp)*/
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<com.acce.gxsc.model.netBean.InCarListBean1>, ResultBean<com.acce.gxsc.model.netBean.InCarListBean1>>() {
                    @Override
                    public ResultBean<com.acce.gxsc.model.netBean.InCarListBean1> call(ResultBean<com.acce.gxsc.model.netBean.InCarListBean1> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }


    public Observable<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>> toOutCarList(String carNo, String boxNo, String time, String timestamp, String hangNo, String contactName, String outCarStatus, String queryTime, String queryType) {
        return HttpClient.getAcceApi()
                .toOutCarList(Constants.ServiceCode.QUERY_OUT_CAR_LIST, new BusinessBuild()
                        .addBusinessParam1("inCarDate", time)
                        .addBusinessParam1("inCarId", "")
                        .addBusinessParam1("plateNum", carNo)
                        .addBusinessParam1("containNo", boxNo)
                        .addBusinessParam1("contactName", contactName)
                        .addBusinessParam1("hangNum", hangNo)
                        .addBusinessParam1("count", 20)
                        .addBusinessParam1("queryType", queryType)
                        .addBusinessParam1("queryTime", queryTime)
                        .addBusinessParam1("timestamp", timestamp)
                        .addBusinessParam1("outCarStatus", outCarStatus)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<com.acce.gxsc.model.netBean.InCarListBean>, ResultBean<com.acce.gxsc.model.netBean.InCarListBean>>() {
                    @Override
                    public ResultBean<com.acce.gxsc.model.netBean.InCarListBean> call(ResultBean<com.acce.gxsc.model.netBean.InCarListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }


    public Observable<ResultBean<Object>> deleteOrder(String pregisterKey) {
        return HttpClient.getAcceApi()
                .deleteOrder(Constants.ServiceCode.DELETE_ORDER, new BusinessBuild()
                        .addBusinessParam1("pregisterKey", pregisterKey)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<Object>> deleteInOrder(String inCarKey) {
        return HttpClient.getAcceApi()
                .deleteOrder(Constants.ServiceCode.DELETE_IN_ORDER, new BusinessBuild()
                        .addBusinessParam1("inCarKey", inCarKey)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<Object>> toOutCar(String inCarId, String outCarRemarks) {
        return HttpClient.getAcceApi()
                .deleteOrder(Constants.ServiceCode.TO_OUT_CAR, new BusinessBuild()
                        .addBusinessParam1("inCarId", inCarId)
                        .addBusinessParam1("dutyId", dutyId)
                        .addBusinessParam1("outCarRemarks", outCarRemarks)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetOutCarReport>> loadOutCarForm() {
        return HttpClient.getAcceApi()
                .loadOutCarForm(Constants.ServiceCode.LOAD_OUT_CAR_FORM, new BusinessBuild()
                        .addBusinessParam1("dutyId", dutyId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetOutCarReport>, ResultBean<NetOutCarReport>>() {
                    @Override
                    public ResultBean<NetOutCarReport> call(ResultBean<NetOutCarReport> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetInBatchListBean>> loadBatchList(String queryId) {
        return HttpClient.getAcceApi()
                .loadBatchList(Constants.ServiceCode.LOAD_BATCH_LIST, new BusinessBuild()
                        .addBusinessParam1("queryId", queryId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetInBatchListBean>, ResultBean<NetInBatchListBean>>() {
                    @Override
                    public ResultBean<NetInBatchListBean> call(ResultBean<NetInBatchListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetSimilarCarInfo>> loadOutCarList(String queryType, String queryId, String plateNum, String containNo, String hangNum, String contactName, String outCarStatus) {
        return HttpClient.getAcceApi()
                .loadOutCarList(Constants.ServiceCode.LOAD_OUT_CAR_LIST, new BusinessBuild()
                        .addBusinessParam1("queryType", queryType)
                        .addBusinessParam1("queryId", queryId)
                        .addBusinessParam1("plateNum", plateNum)
                        .addBusinessParam1("containNo", containNo)
                        .addBusinessParam1("hangNum", hangNum)
                        .addBusinessParam1("contactName", contactName)
                        .addBusinessParam1("outCarStatus", outCarStatus)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetSimilarCarInfo>, ResultBean<NetSimilarCarInfo>>() {
                    @Override
                    public ResultBean<NetSimilarCarInfo> call(ResultBean<NetSimilarCarInfo> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetWorkAreaListBean>> loadWorkAreaList() {
        return HttpClient.getAcceApi()
                .loadWorkAreaList(Constants.ServiceCode.LOAD_POSITION_LIST, new BusinessBuild().build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetWorkAreaListBean>, ResultBean<NetWorkAreaListBean>>() {
                    @Override
                    public ResultBean<NetWorkAreaListBean> call(ResultBean<NetWorkAreaListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<Object>> supervisionCar(String inCarId, String superviseRemarks) {
        return HttpClient.getAcceApi()
                .supervisionCar(Constants.ServiceCode.SUPERVISION_CAR, new BusinessBuild()
                        .addBusinessParam1("inCarId", inCarId)
                        .addBusinessParam1("superviseRemarks", superviseRemarks)
                        .addBusinessParam1("dutyId", dutyId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetBatchDetailBean>> loadBatchDetail(String inBatchId) {
        return HttpClient.getAcceApi()
                .loadBatchDetail(Constants.ServiceCode.LOAD_BATCH_DETAIL, new BusinessBuild()
                        .addBusinessParam1("inBatchId", inBatchId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetBatchDetailBean>, ResultBean<NetBatchDetailBean>>() {
                    @Override
                    public ResultBean<NetBatchDetailBean> call(ResultBean<NetBatchDetailBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetInCarListBean>> getTime(String plateNum, String containNo) {
        return HttpClient.getAcceApi()
                .getTime(Constants.ServiceCode.GET_TIME, new BusinessBuild()
                        .addBusinessParam1("plateNum", plateNum)
                        .addBusinessParam1("containNo", containNo)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetInCarListBean>, ResultBean<NetInCarListBean>>() {
                    @Override
                    public ResultBean<NetInCarListBean> call(ResultBean<NetInCarListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetSupervisionDutyListBean>> loadSupervisionReportList(String queryDate) {
        return HttpClient.getAcceApi()
                .loadSupervisionReportList(Constants.ServiceCode.LOAD_SUPERVISION_HANDOVER_LIST, new BusinessBuild()
                        .addBusinessParam1("atUserId", User.getInstance().getAtUserId())
                        .addBusinessParam1("queryDate", queryDate)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetSupervisionDutyListBean>, ResultBean<NetSupervisionDutyListBean>>() {
                    @Override
                    public ResultBean<NetSupervisionDutyListBean> call(ResultBean<NetSupervisionDutyListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<NetSupervisionListBean>> loadSupervisionHandover(String dutyId, String queryType, String diliveryType, String superviseRemarks, String parkArea) {
        return HttpClient.getAcceApi()
                .loadSupervisionHandover(Constants.ServiceCode.LOAD_SUPERVISION_HANDOVER, new BusinessBuild()
                        .addBusinessParam1("dutyId", dutyId)
                        .addBusinessParam1("queryType", queryType)
                        .addBusinessParam1("superviseRemarks", superviseRemarks)
                        .addBusinessParam1("diliveryType", diliveryType)
                        .addBusinessParam1("parkArea", parkArea)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<NetSupervisionListBean>, ResultBean<NetSupervisionListBean>>() {
                    @Override
                    public ResultBean<NetSupervisionListBean> call(ResultBean<NetSupervisionListBean> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }

    public Observable<ResultBean<Object>> makeupCar(String diliveryType, String plateNumG, String plateNumX, String containNo, String hangNum, String contactName,
                                                    String underCompany, ArrayList<InGoodsBean> pregistergoods, String fee2Id, String fee3Id, String superviseRemarks, String createTime) {
        return HttpClient.getAcceApi()
                .supervisionCar(Constants.ServiceCode.MAKEUP_CAR, new BusinessBuild()
                        .addBusinessParam1("inCarKey", Tools.getBatchKey())
                        .addBusinessParam1("diliveryType", diliveryType)
                        .addBusinessParam1("plateNumG", plateNumG)
                        .addBusinessParam1("plateNumX", plateNumX)
                        .addBusinessParam1("containNo", containNo)
                        .addBusinessParam1("hangNum", hangNum)
                        .addBusinessParam1("contactName", contactName)
                        .addBusinessParam1("underCompany", underCompany)
                        .addBusinessParam1("goods", pregistergoods)
                        .addBusinessParam1("fee2Id", fee2Id)
                        .addBusinessParam1("fee3Id", fee3Id)
                        .addBusinessParam1("createTime", createTime)
                        .addBusinessParam1("superviseRemarks", superviseRemarks)
                        .addBusinessParam1("dutyId", dutyId)
                        .build().toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).map(new Func1<ResultBean<Object>, ResultBean<Object>>() {
                    @Override
                    public ResultBean<Object> call(ResultBean<Object> dutyLogBeanResultBean) {
                        return handleResult(dutyLogBeanResultBean);
                    }
                });
    }
}